package com.ccrfid.rmc6.service.business.prison.door;

import com.ccrfid.rmc6.entity.business.prison.door.InOutDoorEntity;
import com.ccrfid.rmc6.service.amq.MqMsgProducer;
import com.ccrfid.rmc6.util.JsonUtil;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class DoorServiceAspect {
    @Autowired
    private MqMsgProducer mqMsgProducer;

    //新增二道门信息
    @AfterReturning(value = "execution(public * com.ccrfid.rmc6.service.business.prison.door.DoorService.createDoor(..))",
            returning = "ret")
    public void afterCreateDoor(InOutDoorEntity ret) {
        String msg = JsonUtil.INSTANCE.writeValueAsString(ret);
        mqMsgProducer.send2Topic("ws_door_add", msg);
    }

    //修改二道门信息
    @AfterReturning(value = "execution(public * com.ccrfid.rmc6.service.business.prison.door.DoorService.updateDoor(..))",
            returning = "ret")
    public void afterUpdateDoor(InOutDoorEntity ret) {
        String msg = JsonUtil.INSTANCE.writeValueAsString(ret);
        mqMsgProducer.send2Topic("ws_door_update", msg);
    }

    //删除二道门信息
    @AfterReturning(value = "execution(public * com.ccrfid.rmc6.service.business.prison.door.DoorService.deleteDoorById(..)) && args(doorId)",
            argNames = "doorId")
    public void afterDeleteDoor(Long doorId) {
        String msg = JsonUtil.INSTANCE.writeValueAsString(doorId);
        mqMsgProducer.send2Topic("ws_door_delete", msg);
    }
}
